<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>建设单位、施工单位--项目列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/templates/act/process-xl.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form searchForm" action="">
    查询:
    <div class="layui-input-inline">
        <input style="width:200px;" type="text" name="prjName" placeholder="项目名称/申报编号" autocomplete="off"
               class="layui-input">
    </div>
    <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
    <button class="layui-btn" lay-submit lay-filter="formClear">清空</button>
</form>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="toolbarOrg">
    {{# if(org && org.orgType=='1'){ }}
    <div class="layui-btn-container">
        <button class="layui-btn" lay-event="add">新建项目</button>
        <!--<button class="layui-btn" lay-event="add2">新建项目</button>-->
    </div>
    {{# } }}
</script>

<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    {{# if(org && org.orgType=='1'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="change">修改</a>
    {{# } }}
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    var configureCom = {};
    var org;
    var user;
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'matchDict'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var matchDict = layui.matchDict;
        configureCom = layui.configureCom;
        var iframeId = configureCom.GetQueryString('iframeId');
        org = sessionFun.get(configure.SESSION_LOGIN_ORG_DATA);
        user = sessionFun.get(configure.SESSION_LOGIN_USER_DATA);


        var cols = [[
            {
                field: 'prjName', title: '建设项目名称', templet: function (d) {
                    return '<p>' + d.prjName + '</p><p>项目编号:' + (d.prjCode || '-') + '</p>';
                }
            },
            {field: 'buildCorpName', title: '建设单位'},
            {field: 'sgCorpName', title: '施工单位'},
            {field: 'jlCorpName', title: '监理单位'},
            {field: 'sjCorpName', title: '设计单位'},

            // {
            //     field: 'prjCategory', title: '工程项目类别', templet: function (d) {
            //         return '<p>' + matchDict.name(d.prjCategory, configure.PRJ_CATEGORY) + '</p>';
            //     }
            // },
            //{field: 'buildProjectLeaderId', title: '项目负责人'},
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 200}
        ]];
        configureCom.tableRender(configure.UNIT_PROJECT_LIST_HTTP, {}, cols, 'dataList', 10, '', 'toolbarOrg');
        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            sessionFun.remove(configure.SESSION_PROJECT_LIST_DATA);
            switch (obj.event) {
                case 'add':
                    editItem('新建项目', configure.UNIT_PROJECT_CREATE_HTTP, 0);
                    break;
                case 'add2':
                    var i = 5;
                    var interval;
                    var scrollTop;
                    var scrollHeight;
                    var windowHeight;
                    top.layer.open({
                        type: 2,
                        title: '河北省施工图审查管理系统升级说明',
                        shade: 0.8,
                        shadeClose: false,
                        area: ['780px', '580px'],
                        closeBtn: 0,
                        content: '/pages/buidUnit/createProject/upgrade.html',
                        btn: [i + 's后可关闭'],
                        btnAlign: 'c',
                        yes: function (index, layero) {
                            if (i <= 0) {
                                if (scrollTop + scrollHeight === windowHeight) {
                                    top.layer.close(index);
                                } else {
                                    top.layer.msg('请先阅读完,并把滚动条移动到底部!')
                                }
                            }
                        },
                        success: function (layero, index) {
                            var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                            iframeWin.window.onscroll = function () {
                                scrollTop = $(this).scrollTop();
                                scrollHeight = iframeWin.innerHeight;
                                windowHeight = $(this).height();
                            };
                            var fn = function () {
                                top.$(".layui-layer-btn0").text(i + 's后可关闭');
                                i--;
                            };
                            interval = setInterval(function () {
                                fn();
                                if (i === 0) {
                                    top.$(".layui-layer-btn0").text('关闭');
                                    clearInterval(interval);
                                }
                            }, 1000);
                        }
                    });
                        break;
            }
        });
        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_PROJECT_LIST_DATA, data);
            sessionFun.remove(configure.SESSION_PROJECT_WAIT_LIST_DATA, data);
            if (obj.event === 'detail') {
//                editItems('详情', configure.UNIT_PROJECT_DETAIL_HTML);
                editItem('详情', configure.UNIT_PROJECT_UPDATE_HTTP, 1);
            } else if (obj.event === 'change') {
                editItem('修改', configure.UNIT_PROJECT_UPDATE_HTTP, 0);
            } else if (obj.event === 'del') {
                //关闭时重新渲染表格当前页
                top.layer.confirm('确认删除？', {title: '提示'}, function (index) {
                    top.layer.close(index);
                    configureCom.postDataAjax(configure.UNIT_ITEM_DELETE_HTTP, {prjId: data.prjId}).then(function (res) {
                        if (res.code == 0) {
                            top.layer.msg('删除成功！');
                            configureCom.tableReload(true);
                        } else {
                            top.layer.alert('删除失败！');
                        }
                    });
                });
            } else if (obj.event === 'push') {
                //项目批转
                top.layer.open({
                    type: 2,
                    title: '项目申报',
                    area: configureCom.Psize1,
                    content: configureCom.nocache(configure.UNIT_PROJECT_APPLY_DETAIL_HTML, iframeId),
                    success: function (layero, index) {
                        top.layer.full(index);
                    },
                    end: function () {
                        configureCom.tableReload();
                    }
                });
            } else if (obj.event === 'applyRecord') {
                top.layer.open({
                    type: 2,
                    title: '查看记录',
                    area: configureCom.Psize1,
                    content: configureCom.nocache(configure.UNIT_PROJECT_APPLY_LIST_HTML, iframeId),
                    end: function () {
                        configureCom.tableReload();
                    }
                });
            }
        });
        //新增或修改字典详情
        function editItem(title, url, readOnly) {
            sessionFun.set(configure.SESSION_PROJECT_LIST_READONLY, readOnly);
            var btn=['保存'];
            if(readOnly){
                btn=[];
            }
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.UNIT_PROJECT_DETAIL_HTML),
                btn: btn,
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        console.log(res);
                        configureCom.postDataAjax(url, res.result).then(function (res) {
                            console.log(res);
                            top.layer.close(index);
                            top.layer.msg('保存成功！');
                            configureCom.tableReload(true);
                        });
                    });
                },
                success: function (layero, index) {
                    top.layer.full(index);
                }
            });
        }

        //查看详情字典详情
        function editItems(title, url) {
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.UNIT_PROJECT_PROHIBITED_DETAIL_HTML),
                success: function (layero, index) {
                    top.layer.full(index);
                }
            });
        }

        //监听搜索
        configureCom.tableSearch();
    });
</script>
</body>
</html>